home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Cream of the Crop 22
/
Cream of the Crop 22.iso
/
program
/
cgazv4n2.zip
/
CPP.ZIP
/
LLTEST.CXX
< prev
next >
Wrap
C/C++ Source or Header
|
1989-08-27
|
1KB
|
51 lines
// LLTEST.CXX : test for generic linked-list
#include <string.h>
#include <stdio.h>
#include "llist.hxx"
class word {
char * w;
public:
word(char * wrd) {
w = new char[strlen(wrd) + 1];
strcpy(w, wrd);
}
~word() { puts(w); delete w; puts("~word() called"); }
void print() { printf("%s", w); }
};
class wordlist : public llist {
protected:
void delete_data(void * ww) {
delete (word *)ww;
}
public:
// Modify the functions to take and return words:
void append(word * el) { llist::append(el); }
void insert(word * el) { llist::insert(el); }
word * value() { return (word *)llist::value(); }
// add a new function to print the whole list:
void print_list() {
reset();
while(!end()) {
value()->print();
puts("");
next();
}
}
};
#define ADD(X) words.append(new word(#X))
main() {
wordlist words;
ADD(this); ADD(is); ADD(a); /* ADD(test); */ ADD(of);
ADD(the); ADD(linked); ADD(list); ADD(class);
words.print_list();
words.reset();
for(int i = 0 ; i < 3; i++)
words.next();
words.insert(new word("test"));
words.print_list();
}